import Vue from 'vue'
import Router from 'vue-router'
import routers from './router'

Vue.use(Router)
const router = new Router({
  // mode: 'hash',
  // mode: 'history',
  // routes: routers
  routes: routers
})
const HAS_LOGINED = true

router.beforeEach((to, from, next) => {
  if (to.name !== 'login') {
    if (HAS_LOGINED) {
      next()
    } else {
      next({ name: 'login' })
    }
  } else {
    if (HAS_LOGINED) next({ name: 'home' })
    else next()
  }
})
/* router.beforeResolve((to, from, next) => {
  // before
})
router.afterEach((to, from) => {
  // after
}) */
export default router
